<template>
  <el-container class="home-container">
    <el-header>
      <div>
        <img
          src="../assets/2.webp"
          alt=""
          class="logo"
          width="100px"
          height="50px"
        />
        <span>电商管理后台</span>
      </div>

      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollpase ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollpase">|||</div>
        <el-col>
          <el-menu
            background-color="#E2E2D5"
            text-color="#272822"
            active-text-color="#409eff"
            :unique-opened='true'
            :collapse="isCollpase" 
            :collapse-transition="false"
            :router="true"
          

          >
            <el-submenu 
            :index="item.id+'' " 
            v-for="item in menuList"
             :key="item.id"
             >
              <template slot="title">
                <i :class="iconObj[item.id]"></i>
                <span>{{item.authName}}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item :index="'/'+subItem.path+''" v-for="subItem in item.children" :key="subItem.id">
                  <i class="el-icon-menu"></i>{{subItem.authName}}</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
          
          </el-menu>
        </el-col>
      </el-aside>
      <el-main>
        <!-- 欢迎占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      menuList: [],
      iconObj:{
        '125':'iconfont icon-user',
        '103':'iconfont icon-tijikongjian',
        '101':'iconfont icon-shangpin',
        '102':'iconfont icon-danju',
        '145':'iconfont icon-baobiao',
      },
      //折叠false展开
      isCollpase:false
    }
  },
  created() {
    this.getMenuList()
  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    //实现获取数据
    async getMenuList() {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status !== 200) return this.$message.error(res.data.msg)

      this.menuList=res.data;// 把值给上面的数组


    },
    toggleCollpase(){
      this.isCollpase=!this.isCollpase
    }
  },
}
</script>

<style>
.toggle-button{
  text-align: center;
  line-height: 30px;
  height: 30px;
  background-color: #E2E2D5;
  color: white;
  font-size: 10px;
  cursor: pointer;
  letter-spacing: 0.2em;
}
.el-aside{
    border-right: none;
}
.el-aside .el-menu {
  border-right: none;
}
.home-container {
  width: 100%;
  height: 100%;

}
.el-header {
  padding-left: 30px !important;
  background-color: #d1d1c3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #272822;
  font-size: 20px;
}
el-col {
  width: 100%;
}
/* .el-submenu .el-menu-item {
 
  min-width: 199px !important;
} */
.el-header > div {
  display: flex;
  align-items: center;
}
.el-header > div span {
  margin-left: 15px;
}
.el-aside {
  background-color: #E2E2D5;
}
.el-main {
  background-color: #eaedf1;
}
.iconfont{
  margin-right: 10px;
}
</style>